package com.fattyCorps.game.controller;

import com.fattyCorps.game.obj.cache.PlayerInfo;
import com.fattyCorps.game.cache.PlayerCache;
import com.fattyCorps.game.util.GameJwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class TestController {

    @Autowired
    PlayerCache playerCache;

//    @GetMapping("/test")
//    @ApiOperation("测试接口")
//    public String test(){
//        Account account = accountMapper.selectById(7);
//        String ret = "hello test ok：" + account.getAccount();
//        log.info("info输出：" +ret);
//        log.error("error输出：" +ret);
//
//        HeroMould heroMould = heroConfig.getHeroMould(1);
//        List<Integer> skillGroupIdsList = heroMould.getSkillGroupIdsList();
//
//        return ret;
//    }

//    @GetMapping("verifyJWT")
//    public String verifyJWT(String token){
//        DecodedJWT decodedJWT = JwtUtil.verify(token);
//        Integer id = decodedJWT.getClaim("id").asInt();
//        String account = decodedJWT.getClaim("account").asString();
//        return "verifyJWT test ok: id=" + id + " account=" + account;
//    }
//
//    @GetMapping("/add")
//    public String add(){
//        Account account = new Account();
//        account.setAccount("zhangsan");
//        account.setPassword("zsmima123");
////        try{
//            accountMapper.insert(account);
////        }catch (DataAccessException exception){
////            log.info("aktest :" + exception.getMessage() + exception.getCause());
////        }
//        return "";
//    }

    @GetMapping("/del")
    public String del(Integer id){
        return "";
    }

//    @GetMapping("/modify")
//    public String modify(Integer id, String newPwd){
//        Account account = accountMapper.selectById(id);
//        account.setPassword(newPwd);
//        accountMapper.updateById(account);
//        return "";
//    }
//
//    @GetMapping("/select")
//    public String select(Integer id){
//        Account account = accountMapper.selectById(id);
//        return account.getAccount();
//    }

    @PostMapping("/save")
    public String save(HttpServletRequest request) {
        Integer playerId = GameJwtUtils.getPlayerIdByRequest(request);
        PlayerInfo playerInfo = playerCache.getPlayerInfo(playerId);
        playerCache.saveOne(playerInfo);
        return "ok";
    }
}